package test;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import org.xmap.ui.View;
import org.xmap.ui.ViewManager;
import org.xmap.ui.base.Window;
import org.xmap.ui.control.Bitmap;
import org.xmap.ui.views.TextAreaView;

public class BitmapView extends TextAreaView {

    private Bitmap bmp;

    public BitmapView(View back) {
        super(back);
//        this.setBgColor(0x00ffff88);
        this.setTitleText("位图控件演示");
        this.addText("这是个位图控件演示，选择“边框模式”子菜单可以显示或隐藏边框，选择“背景模式”子菜单可以设置背景为透明或可见，选择“图形显示模式”子菜单可以设置图形显示模式。");
        this.bmp = new Bitmap(this.createImage(), 50, 50, 100, 100, Window.ORIENT_LEFT_UP);
        this.bmp.setTransparent(true);
        this.addControls(bmp);
        this.addLeftMenu("边框模式", new String[]{"边框显示", "边框隐藏"});
        this.addLeftMenu("背景模式", new String[]{"背景透明", "背景可见"});
        this.addLeftMenu("图形显示模式", new String[]{"平铺", "居中", "拉伸"});
        this.setRightMenu("返回");
    }
//    public void timeInterrupted() {
//        this.bmp.setLineColor((int) System.currentTimeMillis());
//    }

    public void commandEvent(String command, Window sender) {
        if (command.equals("边框显示")) {
            this.bmp.setDrawRect(true);
        } else if (command.equals("边框隐藏")) {
            this.bmp.setDrawRect(false);
        } else if (command.equals("平铺")) {
//            this.bmp.setBgImageType(Window.IMAGE_TILE);
        } else if (command.equals("居中")) {
//            this.bmp.setBgImageType(Window.IMAGE_CENTER);
        } else if (command.equals("拉伸")) {
//            this.bmp.setBgImageType(Window.IMAGE_STRETCH);
//        } else if (command.equals("随机文字高度")) {
//            int textHeight = Math.abs((int) System.currentTimeMillis()) % 20;
//            textHeight += 20;
//            this.ta.setRowHeight(textHeight);
        } else if (command.equals("背景透明")) {
            this.bmp.setTransparent(true);
        } else if (command.equals("背景可见")) {
            this.bmp.setTransparent(false);
//        } else if (command.equals("短文本")) {
//            this.ta.addText("这是短文本。");
//        } else if (command.equals("长文本")) {
//            this.ta.addText("这是一个超长的文本，添加这个文本将导致换行，就算是屏幕再宽的手机屏幕也会导致换行。");
        } else if (command.equals("返回")) {
            ViewManager.instance.setView(this.back, View.ANIMATION_LEFT_TO_RIGHT);
        }
    }

    private Image createImage() {
        Image i = Image.createImage(30, 30);
        Graphics g = i.getGraphics();
        g.setColor(0xffff0000);
        g.fillRect(0, 0, 100, 100);
        g.setColor(0xff00ff00);
        g.drawString("测试", 0, 0, Graphics.LEFT | Graphics.TOP);
        return i;
    }
}
